package com.fdb.efp.console.route.impl;

import com.fdb.basic.framework.core.util.StringUtil;
import com.fdb.efp.console.common.vo.EngineVO;
import com.fdb.efp.console.executor.RoutePluginExecutor;
import com.fdb.efp.console.service.vo.BizFlowRouteVO;
import com.fdb.efp.console.service.facade.DynamicExecuteDrools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * 
 * 动态路由规则执行器
 * 
 * @author Cytus_
 * @since 2018年6月2日 上午11:51:58
 * @version 1.0
 *
 */
@Service("defaultRouteDynamicDroolsExecutor")
public class DefaultRouteDynamicDroolsExecutor implements RoutePluginExecutor {
    
    private static Logger logger = LoggerFactory.getLogger(DefaultRouteDynamicDroolsExecutor.class);
    
    @Autowired
    @Qualifier("dynamicExecuteDrools")
    private DynamicExecuteDrools dynamicExecuteDrools;

    public boolean judgeRoute(EngineVO evo, BizFlowRouteVO routeVo) throws Exception {
        
        boolean result = false;
        
        try {
            result = dynamicExecuteDrools.dynamicExecuteDrools(routeVo.getBizRouteId(), routeVo.getBizRouteRule(), evo.getPluginVo().getVos());
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw e;
        }
        
        return result;
    }

    public boolean isDefault(BizFlowRouteVO routeVo) {
        return StringUtil.isEmpty(routeVo.getBizRouteRule());
    }
}
